﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using dIRca.Network;
using dIRca.Data;

namespace dIRca.Console
{
    class Program
    {
        private static ConnectionManager _connectionManager;

        static void Main(string[] args)
        {
            System.Console.WriteLine("Connecting to server.");
            System.Console.WriteLine();
            System.Console.WriteLine("Type your raw message and press <Enter> to send.\nPress !quit to quit.");
            _connectionManager = new ConnectionManager();
            _connectionManager.MessageReceived += new EventHandler<MessageEventArgs>(_connectionManager_MessageReceived);
            _connectionManager.MessageSent += new EventHandler<MessageEventArgs>(_connectionManager_MessageSent);
            _connectionManager.Connect();
            while (true)
            {
                var consoleInput = System.Console.ReadLine();
                if (consoleInput == "!quit")
                    Environment.Exit(0);
                _connectionManager.SendMessage(consoleInput);
            }
        }

        static void _connectionManager_MessageSent(object sender, MessageEventArgs e)
        {
            System.Console.WriteLine(e.Message.TimeStamp.ToString() + " " + e.Message.Data);
        }

        static void _connectionManager_MessageReceived(object sender, MessageEventArgs e)
        {
            System.Console.WriteLine(e.Message.TimeStamp.ToString() + " " + e.Message.Data);
        }
    }
}
